#include "soaC2SignalToEdc.h"
#include "public_define.h"
#include "adr_component.h"

SoaC2SignalToEdc::SoaC2SignalToEdc()
{

}

SoaC2SignalToEdc::~SoaC2SignalToEdc()
{

}

SoaC2SignalToEdc &SoaC2SignalToEdc::getInstance()
{
    static SoaC2SignalToEdc instance;
    return instance;
}

void SoaC2SignalToEdc::setPublishHandle(adr_component *component)
{
    m_component = component;
}

void SoaC2SignalToEdc::sendSignal(const std::string &signals)
{
    static int sigSend = 0;
    if (sigSend == 500)
    {
        sigSend = 0;
        Log_ERROR("send signal shot to edc: {}", signals);
    }
    sigSend++;

    Log_Signal("send signal shot to edc: {}", signals);
    if (m_component == nullptr)
    {
        Log_ERROR("[SoaC2SignalToEdc][sendSignal] component empty... ");
        return;
    }
    m_component->publish(signals, "adr-AdrTrigger.SignalSnapshot");
}

void SoaC2SignalToEdc::sendSignalToMqtt(const std::string &signals)
{
    static int sigSend1 = 0;
    if (sigSend1 == 500)
    {
        sigSend1 = 0;
        Log_ERROR("send signal shot to edc: {}", signals);
    }
    sigSend1++;
    if (m_component == nullptr)
    {
        Log_ERROR("[SoaC2SignalToEdc][sendSignal] component empty... ");
        return;
    }
    Log_Info("gd send mqtt collect signal : {} ",signals);
    m_component->publish(signals, "adr-string-SignalAgent");
}

void SoaC2SignalToEdc::sendEvent(const std::string &event)
{
    Log_Info("send event to edc: {}", event);
    if (m_component == nullptr)
    {
        Log_ERROR("[SoaC2SignalToEdc][sendEvent] component empty... ");
        return;
    }
    m_component->publish(event, "adr-string-EventSnapshot");
}